import urllib.parse
import urllib.request
import tkinter.messagebox
import tkinter.simpledialog
import time

url = 'https://www.chiphell.com/forum-26-1.html'

keyword = tkinter.simpledialog.askstring('提示', '输入抓取关键词', initialvalue = '3090')
cookie = tkinter.simpledialog.askstring('提示', '输入cookie', initialvalue = '')

while True:
    req = urllib.request.Request(url)
    req.add_header('cookie', cookie)
    req.add_header('user-agent', "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
    try:
        response = urllib.request.urlopen(req)
        content = response.read().decode("utf8")
        if content.find(keyword) != -1:
            tkinter.messagebox.showinfo('提示', '有人在卖[' + keyword + ']赶紧去抢！')
            break
    except urllib.error.HTTPError as e:
        print(e.code)
    time.sleep(5)